//
//  YZMCardShowView.m
//  YZMicroStock
//
//  Created by wangminhong on 16/7/12.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZMCardShowView.h"

@interface YZMCardShowView()

@property (nonatomic, strong) UIImageView *iconIV;
@property (nonatomic, strong) UILabel *nameLB;
@property (nonatomic, strong) UIImageView *arrowIV;
@end

@implementation YZMCardShowView

- (instancetype)init{
    
    return [self initWithFrame:CGRectMake(0, 0, 1, 1)];
}

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createObjects];
    }
    
    return self;
}

- (void)setCard:(YZMBankCardModel *)card{
    
    if (!card) {
        
        self.iconIV.image = [UIImage imageNamed:@"icon_bg_plus_dis"];
        self.nameLB.text = @"添加银行卡";
    }else{
        
        self.iconIV.image = [card iconImage];
        self.nameLB.text = [card.bankName stringByAppendingFormat:@" 尾号%@",[card.cardNumber tailNumber]];
    }
}

- (void)createObjects{
    self.backgroundColor = [YZMAppStyle colorForMain];

    self.iconIV = [UIImageView new];
    self.iconIV.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:self.iconIV];
    [self.iconIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.centerY.equalTo(self);
        make.height.mas_equalTo(24);
    }];
    
    self.nameLB = [YZMAppStyle labelWithMediumWhite];
    [self addSubview:self.nameLB];
    [self.nameLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(20);
        make.bottom.equalTo(self).offset(-20);
        make.left.equalTo(self.iconIV.mas_right).offset(12);
    }];
    
    self.arrowIV = [UIImageView new];
    self.arrowIV.image = [UIImage imageNamed:@"icon_gray_right_arrow"];
    [self addSubview:self.arrowIV];
    [self.arrowIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(12);
        make.centerY.equalTo(self);
        make.right.equalTo(self).offset(-15);
    }];
}

@end
